<?
namespace xto\data;

use think\Db;

class Sql{
	static function insert($table,$data){
		return db($table)->insert($data);
	}

	static function update($talbe,$data,$map=null){
		if(is_null($map)){
			return Db::table($talbe)->update($data);
		}else{
			return Db::table($talbe)->where($map)->update($data);
		} 
	}

	static function saveorupdate($table,$data,$map){
		$c=Sql::count($table,$map);
		if($c<=0){
			return Sql::insert($table,$data);
		}else{
			return Sql::update($table,$data,$map);
		}
	}

	static function getfield($talbe,$map,$field){
		return Db::table($talbe)->where($map)->value($field);
	}

	static function select($table,$map){
		return Db::table($table)->where($map)->select();
	}

	static function find($table,$map){
		return Db::table($table)->where($map)->find();
	}

	static function count($table,$map){
		return Db::table($table)->where($map)->count();
	}
}